﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict.Blo;

namespace UI
{
    public class PetInfoTab : MonoBehaviour
    {
        public UILabel level;
        public UILabel zizhi;//资质
        public UILabel breachLevel;//突破等级
        public UILabel intimacyLevel;//亲密度等级

        public GameObject twoLines;
        public List<PetAttributeLabel> list4;
        public GameObject threeLines;
        public List<PetAttributeLabel> list6;
        public GameObject talentRoot;
        public GameObject petAttributeItem;
        public GameObject petTalentItem;
        
        private UIPet petData;
        public void SetPet(string guid)
        {
            petData = StaticData.playerData.GetUIPet(guid);
            if(petData.propCount <= 4)
            {
                twoLines.SetActive(true);
                CreateLabels(list4);
            }
            else
            {
                threeLines.SetActive(true);
                CreateLabels(list6);
            }
            int y = -16;
            int totalHeight = 0;
            talentRoot.transform.DestroyChildren();
            for(int i = 0; i < petData.talentBranch.Count; i++)
            {
                var tal = TableTalentBlo.GetTalentById(petData.talentBranch[i]);
                var go = Instantiate(petTalentItem);
                go.SetActive(true);
                go.transform.parent = talentRoot.transform;
                go.transform.localScale = new Vector3(1, 1, 1);
                go.transform.localPosition = new Vector3(0, y, 0);
                go.GetComponent<PetTalentItem>().SetTalent(tal.Name,tal.Desc);
                y -= go.GetComponent<PetTalentItem>().PetTalentItemHeight;
                totalHeight += go.GetComponent<PetTalentItem>().PetTalentItemHeight;
            }
            Vector3 size = talentRoot.GetComponent<BoxCollider>().size;
            talentRoot.GetComponent<BoxCollider>().size = new Vector3(size.x, totalHeight, size.z);
        }
        public void CreateLabels(List<PetAttributeLabel> list)
        {
            var flag = 0;
            foreach(var pet in petData.petProps)
            {
                var temp = new BaseAttributeData(pet.prop);
                var tt = 0.0;
                var id = "";
                for (int i = 0; i < temp.attributes.Length; i++)
                {
                    if (temp.attributes[i] != 0.0)
                    {
                        tt = temp.attributes[i];
                        id = BaseAttributeData.GetDictPropIdByIndex(i);
                    }
                }
                if (pet.state == 1)//解锁了
                {
                    if (list[flag] != null)
                    {
                        list[flag].SetLabel(id, tt.ToString());
                    }
                }
                else
                {
                    if (list[flag] != null)
                    {
                        list[flag].SetLabel(id, tt.ToString(),true);
                        
                    }
                }
                list[flag].gameObject.SetActive(true);
                flag++;
            }
        }
    }
}
